package world;

import java.awt.Point;

import Default.Manager;
import Default.Variables;

public class Target {
	public int speed;
	public int volume;
	public Point start=new Point();
	public Point end=new Point();
	public Point location=new Point();
	public int start_time;
	public double angle;
	
	//public Target()

	public boolean setNewLocation()
	{
		//System.out.println("star: "+start);
		int time=Time.time;
		int distance=speed*(Math.abs((time-start_time)));
		double newX=(Math.abs(Math.sin(Math.toRadians(angle))*distance));
		//System.out.println("star: "+start);
		//System.out.println("newX: "+newX);
		double newY=(Math.abs(Math.cos(Math.toRadians(angle))*distance));
		//System.out.println("newY: "+newY);
		if(start.x<end.x)
			location.x=start.x+(int)newX;
		else
			location.x=start.x-(int)newX;
		//System.out.println("hi 1");
		if(location.x<Variables.sense_radius)
			return false;
		if(location.x>(Variables.sense_radius+Variables.x-1))
			return false;
		
		
		if(start.y<end.y)
			location.y=start.y+(int)newY;
		else
			location.y=start.y-(int)newY;
		if(location.y<Variables.sense_radius)
			return false;
		if(location.y>(Variables.sense_radius+Variables.y-1))
			return false;
		
		//System.out.println("hi 2");
		//update the sensors
		for(int i=0;i<Variables.sense_radius*2+1;i++)
		{
			for(int j=0;j<Variables.sense_radius*2+1;j++)
			{
				
				if(Variables.grid[location.y+i-Variables.sense_radius][location.x+j-Variables.sense_radius]>0)//there is sensor
				{
					/**
					 * 
					 *
					if(World.masks.get(volume)[i][j]!=0)
						Manager.cntAgents++;
						*/
					
					/*System.out.print("get sense "+Variables.grid[location.y+i-Variables.sense_radius][location.x+j-Variables.sense_radius]+" ");
					System.out.println("i: "+i+" j: "+j+", "+World.masks.get(volume)[i][j]);
					*/
					Variables.manager.all_agents.get(Variables.grid[location.y+i-Variables.sense_radius][location.x+j-Variables.sense_radius]-1).senseVol+=World.masks.get(volume)[i][j];
				}
			}
		}
		
		//System.out.println("star: "+start);
		//System.out.println(location);
		return true;
	}
	public void getAngle()
	{
		double near=/*Math.abs(*/start.y-end.y/*)*/;
		double far=/*Math.abs(*/start.x-end.x/*)*/;
		//System.out.println("far: "+far+" near: "+near);
		
		angle=Math.toDegrees(Math.atan(far/near));
		//System.out.println(angle);
		//return tmp;
	}
}
